<template>
	<div class="container" v-title data-title='绑定公司'>
		<div class="page">
		 <header class="header mb10">
            <div class="qs-tab-nav">
                <div class="item" v-on:click="toggleTab(1)">
                    <a href="javascript:void(0)" :class="{active:isShow}" @click="loadCompanyStatus()">绑定公司代码</a>
                </div>
                <div class="item" v-on:click="toggleTab(2)">
                    <a href="javascript:void(0)" :class="{active:!isShow}" @click="loadCompanyStatus()">注册公司<font style="color:red;"v-if="status">—{{status}}</font></a>
                </div>
            </div>
        </header>
        <component :is="currentView"></component>
		<!--<bind_company_content></bind_company_content>-->
		<!--<register_company></register_company>-->
		</div>
	</div>
</template>
<script>
import bind_company_content from './bindCompanyContent.vue'
import register_company from './registerCompany.vue'
	export default{
		data(){
			return {
				currentView:'bind_company_content',
				isShow:true,
				status:""
			}
		},
		mounted: function() {
			this.loadCompanyStatus();
		},
		methods:{
			toggleTab:function(op){
				var _self = this;
				if(2==op){
					_self.isShow =false;
					_self.currentView = 'register_company';
				}else{
					_self.isShow =true;
					_self.currentView = 'bind_company_content';
				}
			},
			loadCompanyStatus:function(){
				//加载公司信息
				var _self = this;
				var body = {};
				body.params = {};
				var url = this.utilHelper.apiUrl+'/api/getCompanyByUserId';
				_self.$http.post(url,body).then((response)=>{
					var body = response.body
					if(body.result==1){
						var company = body.resData.company;
						var companyType = company.companyType;
						var userRole = window.localStorage.getItem("3_userRole");
						var status =  company.status;
						if(companyType == '20' && userRole == '-1') {
							_self.status = '';
						}else {
							if (status == '0') {
								_self.status = '待审核';
							}else if (status == '1') {
								_self.status = '审核失败';
							}else if (status == '2') {
								_self.status = '审核成功';
							}
							_self.getPartnerInfo();//更新用户缓存信息
						}
					}
				})
			},
			 //实时获取用户信息
            getPartnerInfo(){
		        var _self = this;
		        var body = {};
		        body.params = {}
		        var url = this.utilHelper.apiUrl+'/api/getUserById';
		          _self.$http.post(url, body).then((response) => {
		              var data = response.body.resData;
		              var result = data.result;
		              if (result == "1") {
		                window.localStorage.setItem("3_userId", data.id);
                        window.localStorage.setItem("3_userName", data.accountName);
                        window.localStorage.setItem("3_phone", data.phone);
                        window.localStorage.setItem("3_isLogin", true);
                        window.localStorage.setItem("3_userRole", data.userRoleId);
                        window.localStorage.setItem("3_accountType",data.accountType);
		              }
		          });
		    }
		},
		components:{
			bind_company_content,register_company
		}
	}
	
</script>
<style scoped>
	@import url("../../assets/css/global.css");
	@import url("../../assets/css/style.css");
	input, textarea, img {
    vertical-align: middle;
	    font-family: Arial, "Microsoft Yahei";
	}
	input, textarea {
	    outline: none;
	}
	input, textarea, button {
	    -webkit-appearance: none;
	}
	input, textarea, button {
	    -webkit-appearance: none;
	}
</style>